
var newer = newer || {};
newer.gd = newer.gd || {};

newer.MembersDiv = function(o) {
	this.domNode = o.domNode;
	this.prt = o.prt;	
	
	this.init();
}

newer.MembersDiv.prototype = {
	init: function() {
		this.domNode.html("");
		
		this.domNode.removeClass("nw-event-listener").addClass("nw-event-listener");
		this.domNode.on("nw-event", $.proxy(this.nweHandler,this));
		
		this.refresh();
	}, 
	
	refresh: function() {
		this.update();
	},
	
	nweHandler: function(e,c) {
		if (c.type == newer.EventHelper.DATA_TYPE) {
			if (c.props.type == "member") {
				this.refresh();
			}
		}
	},
	
	update: function() {
		this.domNode.html("");
		this.domNode.append('<div id="members-div" class="people-gallery-area"></div>');
		this.membersNode = $("#members-div");
		this.showMembers(this.membersNode);
	}, 
	
	updatePhotoSrc: function(people) {
			if(people.hasPhoto==true) {
				$("img#f"+people.id).attr("src", "/Photos/displayUserPhoto?id="+people.id+"&s="+Math.random());
			} else {
				$("img#f"+people.id).attr("src", "/public/images/default-user-image");
			}
	},
	
	showOneMember: function(person) {
		var res = "<div class=\"inline-block\"><img height=150px id=\"f" + person.id +"\" class=\"friends-photo-img\"></div>";
		
		return res;
	},
	
	showMembers: function(node) {
		var self = this;
		$.post("/Circles/getMembersByCircleId", {"cid":newer.gd.circle.id}, function(result) {
			if (result.error == "Circle has no members") {
				//$(settings.divSelector).append(result.error + "<br/><br/>");
			} else {
				$.each(result, function(index, member) {
					node.append('<div id="member-div-m'+member.id+'" style="display:inline-block"></div>');
					new newer.PeopleCard({
						domNode: $("#member-div-m"+member.id),
						idSuffix: "member-"+member.id,
						personInfo: member
					});
					//$("#member-div-m"+member.id).on("click", {pid:member.id, self:self},newer.PeopleHelper.gotoPeopleHandler).addClass("link-like-element");
				});
			}
		}, "json");
	}
}